import { i18n as validator } from 'sneakxy-validator';
const ilocales = {
    "zh-CN": import('view-design/dist/locale/zh-CN'),
    "en-US": import('view-design/dist/locale/en-US')
};

const locales = {
    "zh-CN": import('locale/zh-CN.js'),
    "en-US": import('locale/en-US.js')
};

const validations = {
    "zh-CN": import('sneakxy-validator/src/locale/zh-CN.js'),
    "en-US": import('sneakxy-validator/src/locale/en-US.js')  
}

const defaultLocale = "zh-CN";

var autoLocale = navigator.language || navigator.browserLanguage || defaultLocale;

export const locale = locales[autoLocale] && ilocales[autoLocale] ? autoLocale : defaultLocale;

function messages() {
    return new Promise(resolve => {
        const messages = {};
        locales[locale].then( ({default: i18n}) => {
            ilocales[locale].then( ({default: lang}) => {
                validations[locale].then(({default: validation}) => {
                    messages[locale] = Object.assign(i18n, lang);
                    validator(validation);
                    resolve(messages);
                });
            });
        });
    });
}

export default async () => {
    return await messages();
};